
import axios from 'axios';
axios.defaults.baseURL = '/api';
axios.defaults.timeout = 6000


// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么

  let token = localStorage.getItem('token');
  console.log(token)
  if (token) {
    config.headers.authorization = token;
  } else {
    console.log(111)
  }

  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  // if (response.data.code === 401) {
  //   message.success('token失效');
  //   window.location.pathname = "/"
  // }
  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});


export const postUrl = async (url, params) => await axios.post(url, params);

export const getUrl = async (url, params) => await axios.get(url, { params });

export const putUrl = async (url, params) => await axios.put(url, params);

export const delUrl = async (url, params) => await axios.delete(url, { params });